import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_fgbg/flutter_fgbg.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  group('FGBGEvents', () {
    test('instance should be a singleton', () {
      final instance1 = FGBGEvents.instance;
      final instance2 = FGBGEvents.instance;
      expect(instance1, same(instance2));
    });

    test('last should initially be foreground', () {
      expect(FGBGEvents.last, equals(FGBGType.foreground));
    });

    test('ignoreWhile should ignore events during closure', () async {
      bool eventSent = false;
      final subscription = FGBGEvents.instance.stream.listen((_) {
        eventSent = true;
      });

      await FGBGEvents.ignoreWhile(() async {
        // 模拟事件发送，但应该被忽略
        // 这里无法直接触发原生事件，所以测试ignoreWhile的基本行为
      });

      expect(eventSent, isFalse);
      await subscription.cancel();
    });
  });

  group('FGBGType', () {
    test('should have foreground and background values', () {
      expect(FGBGType.values.length, equals(2));
      expect(FGBGType.values, contains(FGBGType.foreground));
      expect(FGBGType.values, contains(FGBGType.background));
    });
  });
}